//
//  ContentView.swift
//  LocationChange
//
//  Created by True on 2024/7/2.
//

import SwiftUI
import Foundation


struct DataModel {
    var gpxFiles: [String]
    
    init() {
        let urls = Bundle.main.paths(forResourcesOfType: "gpx", inDirectory: nil)
        gpxFiles = urls
    }
}


@Observable
class ViewModel {
    var dataModel: DataModel
    
    var fileNames: [String] {
        dataModel.gpxFiles.map{ path in
            FileManager.default.displayName(atPath: path)
        }
    }
    
    init() {
        dataModel = DataModel()
        print(dataModel)
    }
}


struct ContentView: View {
    
    @State private var vm:ViewModel = ViewModel()
    
    var body: some View {
        GroupBox {
            VStack(spacing: 10) {
                Image(systemName: "globe")
                    .imageScale(.large)
                    .foregroundStyle(.tint)
                
                // Spacer(minLength: 10)
                
                ForEach(vm.fileNames, id: \.self) { name in
                    Text(name)
                }
            }
            .padding()
        } label: {
            Text("地理坐标点")
        }
        .padding()

    }
}

#Preview {
    ContentView()
}
